﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IDAL;

namespace KPIS.GERP.GFMS.DAL
{
    public class D_HRM_MAS_Provinces : IDAL_HRM_MAS_Provinces
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        ConvertNullable cn = new ConvertNullable();
        

        public D_HRM_MAS_Provinces()
        {

        }

        public IList<M_HRM_MAS_Provinces> GetList(Nullable<int> region_seq)
        {
            string strSQL;
            DataRowCollection drc = null;
            IList<M_HRM_MAS_Provinces> infoList = new List<M_HRM_MAS_Provinces>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);

                dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);
                dbManager.AddParameters(1, "@region_seq", region_seq);

                strSQL = "SELECT prov_seq, prov_name"
                    + " FROM mas_provinces"
                    + " WHERE record_status not like @delete_status"
                    + (region_seq != null ? " and region_seq = @region_seq" : "")
                    + " ORDER BY prov_name";
                

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_HRM_MAS_Provinces info = new M_HRM_MAS_Provinces();
                        info.prov_seq = Convert.ToInt32(drc[i]["prov_seq"]);
                        info.prov_name = drc[i]["prov_name"].ToString();
                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }
    }
}
